package com.itcs.app.tran;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.itcs.box.BoxConstants;
import com.itcs.box.domain.BoxRequest;
import com.itcs.box.util.LogUtils;
import com.itcs.dubbo.service.DubboServiceAdapter;

/**
 * @ClassName: BoxTran1008
 * @Description: 支付成功通知应答
 * @author CHEN-HF
 * @date 2017年12月22日 上午11:29:23
 * 
 */
@Component
public class BoxTran1008 implements DubboServiceAdapter {

	private Log logger = LogFactory.getLog(getClass());

//	@Autowired
//	private TransJournalMapper transJournalMapper;

	@Override
	public String getTrancode() {
		return "box_1008";
	}

	public String getTranDescription() {
		return "支付成功通知应答";
	}

	@Override
	public Map<String, Object> exchange(Map<String, Object> reqRecord) {
		

		logger.info(LogUtils.build(getTrancode(), getTranDescription(), "接收支付通知应答", JSON.toJSONString(reqRecord)));

		Map<String, Object> res = new HashMap<>();
		try {
			BoxRequest boxRequest = (BoxRequest) reqRecord.get(BoxConstants.BOX_REQ_KEY);
			this.handle(boxRequest); // 业务处理
		} catch (Exception e) {
			// resData.put("result", "-2"); // 其他异常或数据库异常
			logger.error(LogUtils.build(getTrancode(), getTranDescription(), "处理失败," + e.getMessage()), e);
		}

		logger.info(LogUtils.build(getTrancode(), getTranDescription(), "接收支付通知应答处理完成"));

		return res;
	}

	public void handle(BoxRequest boxRequest) {

//		TransJournal transJournal = transJournalMapper.selectByPrimaryKey(boxRequest.getData().getTransacSeq());
//
//		if (boxRequest.getData().getResult() != null && boxRequest.getData().getResult().equals("1")) { // 判断2008下发结果
//			if (transJournal.getPayState() == 2) { // 支付成功，应答完成交易
////				transJournal.setPayState(5); // 支付成功应答，完成交易,完成交易为1009交易
////				transJournalMapper.updateByPrimaryKey(transJournal);
//			} else {
//				logger.warn(LogUtils.build(getTrancode(), getTranDescription(), "该交易为支付失败或已完成支付车道交易"));
//			}
//		} else {
//			logger.warn(LogUtils.build(getTrancode(), getTranDescription(), "接收支付通知应答处理失败result:"+boxRequest.getData().getResult()));
//		}
	}

}
